﻿/* 
 * Godtear.com
 * QQ:bzure@189.cn
 *Author:Nathan Liu
 */
using System;
using System.Collections.Generic;
using System.Text;
using Bzure.Common.ObjectFactory;

namespace Bzure.Common.Configuration.AppConfiguration
{
    public class DefaultConfigObjectFactory<T> : IConfigObjectFactory<T>
       where T : class
    {
        public T CreateInstance(ReflectConfigSection configSection)
        {
            object newObject = null;
            try
            {
                Type type = Type.GetType(configSection.ComponentType);

                if (type != null)
                {
                    newObject = ReflectionFactory.Create().Build(type, configSection.Params);  
                }
                if (newObject != null && newObject is T)
                    return newObject as T;              
            }
            catch (Exception e)
            {
            }
            return default(T);
        }
    }
}
